import https from '../../../utils/request2.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo: {},
    studentNumber: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.userinfoclick()
  },
  handleContact(e) {

  },
  async userinfoclick() {
    let that = this
    let { studentNum } = JSON.parse(wx.getStorageSync('studentToken'))
    let options = {
      url: '/open/system/getStudentByStudentNumber',
      method: 'get',
      data: { studentNumber: studentNum },
      header: { "content-type": "application/json;charset=UTF-8" }
    }
    let res = await https(options)  // Now this await is valid
    console.info(res, 'res')
    if (res && res.data.code == 200) {
      let match = res.data.data.schoolName.match(/\((\d+)\)/);
      let studentNumberbox = match ? match[1] : null;

      this.setData({ userinfo: res.data.data, studentNumber: studentNumberbox })
      this.setData({phoneNumber:JSON.parse(ress.data.msg).phoneNumber})
    } else {
      wx.showToast({
        title: res.data.msg,
      })
      // this.setData({attention:ress.data.mes}) 
    }
  },
  logout() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          wx.removeStorageSync('token')
          wx.removeStorageSync('studentToken')
          wx.showToast({
            title: '已退出登录',
            icon: 'success'
          })
          console.log('执行了');

          wx.reLaunch({
            url: '/pages/homework/login/login',
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.hideTabBar({ animation: false });
    if (this.getTabBar && this.getTabBar()) {
      this.getTabBar().refreshTabBar(); 
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})